/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Permissive License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Permissive License, please send an email to 
 * ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Permissive License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 *
 * ***************************************************************************/

using System;
using System.IO;
using System.Diagnostics;
using System.Globalization;
using System.Threading;
using System.Collections.Generic;
using Microsoft.Scripting;
using Microsoft.Scripting.Internal;
using Microsoft.Scripting.Internal.Ast;
using Microsoft.Scripting.Internal.Generation;
using Microsoft.Scripting.Hosting;
using System.Reflection;
using System.Reflection.Emit;
using Nua;
using Nua.Hosting;
using Nua.Ast;

namespace Nua.Compiler.Generation 
{
    public class NuaScriptCompiler : ScriptCompiler {

        public new NuaEngine Engine {
            get { return (NuaEngine)base.Engine; }
        }

        internal NuaScriptCompiler(NuaEngine engine)
            : base(engine) {            
        }

        public NuaScriptCompiler()
            : base(NuaEngine.CurrentEngine) {

        }

        public override CodeBlock ParseInteractiveCode(CompilerContext cc, bool allowIncomplete, out InteractiveCodeProperties properties) 
        {
            throw new NotImplementedException();          
        }

        public override CodeBlock ParseExpressionCode(CompilerContext cc) 
        {
           throw new NotImplementedException();
        }

        public override CodeBlock ParseStatementCode(CompilerContext cc) 
        {
            throw new NotImplementedException();
        }

        public override CodeBlock ParseFile(CompilerContext cc) 
        {
            CodeBlock block = new CodeBlock("test", null, null);
            Scanner scanner = new Scanner(cc.Errors, cc.SourceUnit);
            Parser parser = new Parser(scanner, block, cc.Errors);

            Statement s = parser.Result;

            foreach (Var v in parser.variables)
                block.AddReference(((NamedVar)v).Reference);            

            return block;

        }

        #region Implementation

        public static CodeBlock BindAndTransform(CompilerContext context, Statement statement, bool module) 
        {
            return BindAndTransform(context, statement, module, false);
        }

        public static CodeBlock BindAndTransform(CompilerContext context, Statement statement, bool module, bool print) 
        {
            throw new NotImplementedException();
        }

        public override SourceUnit ParseCodeDom(System.CodeDom.CodeObject codeDom) 
        {
            //return new PythonCodeDomCodeGen().GenerateCode(Engine, codeDom);
            throw new NotImplementedException();
        }
        
        #endregion
    }
}
